package com.yic.module.device.service.inspectionRecordInfo;

import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;

import java.util.*;
import com.yic.module.device.controller.admin.inspectionRecordInfo.vo.*;
import com.yic.module.device.dal.dataobject.inspectionRecordInfo.InspectionRecordInfoDO;
import com.yic.framework.common.pojo.PageResult;

import com.yic.module.device.convert.inspectionRecordInfo.InspectionRecordInfoConvert;
import com.yic.module.device.dal.mysql.inspectionRecordInfo.InspectionRecordInfoMapper;

import static com.yic.framework.common.exception.util.ServiceExceptionUtil.exception;
import static com.yic.module.device.enums.ErrorCodeConstants.*;

/**
 * 巡检/点检记录明细 Service 实现类
 *
 * @author 系统管理员
 */
@Service
@Validated
public class InspectionRecordInfoServiceImpl implements InspectionRecordInfoService {

    @Resource
    private InspectionRecordInfoMapper inspectionRecordInfoMapper;

    @Override
    public Long createInspectionRecordInfo(InspectionRecordInfoCreateReqVO createReqVO) {
        // 插入
        InspectionRecordInfoDO inspectionRecordInfo = InspectionRecordInfoConvert.INSTANCE.convert(createReqVO);
        inspectionRecordInfoMapper.insert(inspectionRecordInfo);
        // 返回
        return inspectionRecordInfo.getId();
    }

    @Override
    public void updateInspectionRecordInfo(InspectionRecordInfoUpdateReqVO updateReqVO) {
        // 校验存在
        validateInspectionRecordInfoExists(updateReqVO.getId());
        // 更新
        InspectionRecordInfoDO updateObj = InspectionRecordInfoConvert.INSTANCE.convert(updateReqVO);
        inspectionRecordInfoMapper.updateById(updateObj);
    }

    @Override
    public void deleteInspectionRecordInfo(Long id) {
        // 校验存在
        validateInspectionRecordInfoExists(id);
        // 删除
        inspectionRecordInfoMapper.deleteById(id);
    }

    private void validateInspectionRecordInfoExists(Long id) {
        if (inspectionRecordInfoMapper.selectById(id) == null) {
            throw exception(INSPECTION_RECORD_INFO_NOT_EXISTS);
        }
    }

    @Override
    public InspectionRecordInfoDO getInspectionRecordInfo(Long id) {
        return inspectionRecordInfoMapper.selectById(id);
    }

    @Override
    public List<InspectionRecordInfoDO> getInspectionRecordInfoList(Collection<Long> ids) {
        return inspectionRecordInfoMapper.selectBatchIds(ids);
    }

    @Override
    public PageResult<InspectionRecordInfoDO> getInspectionRecordInfoPage(InspectionRecordInfoPageReqVO pageReqVO) {
        return inspectionRecordInfoMapper.selectPage(pageReqVO);
    }

    @Override
    public List<InspectionRecordInfoDO> getInspectionRecordInfoList(InspectionRecordInfoExportReqVO exportReqVO) {
        return inspectionRecordInfoMapper.selectList(exportReqVO);
    }

    @Override
    public List<InspectionRecordInfoDO> getAppInspectionRecordInfoList(InspectionRecordInfoExportReqVO exportReqVO) {
        return inspectionRecordInfoMapper.selectAppList(exportReqVO);
    }

    @Override
    public PageResult<InspectionRecordInfoDO> getPcInspectionRecordInfoPage(InspectionRecordInfoPageReqVO pageReqVO) {
        return inspectionRecordInfoMapper.selectPcPage(pageReqVO);
    }

    @Override
    public void updateStatus(InspectionRecordInfoUpdateReqVO updateReqVO) {
        inspectionRecordInfoMapper.updateStatus(updateReqVO.getStatus(),updateReqVO.getId());
    }

}
